package com.example.monitorsms;

import android.content.Intent;
import android.content.SharedPreferences;
import android.os.Bundle;
import android.provider.Settings;
import android.widget.Button;
import android.widget.EditText;

import com.example.monitorsms.service.MyNotificationListenerService;
import com.example.monitorsms.utils.StringUtils;

public class DemoActivtiy extends BaseActivity {
    private EditText editText;

    @Override
    protected int getLayoutId() {
        return R.layout.activity_demo;
    }

    @Override
    protected void main(Bundle savedInstanceState) {
        super.main(savedInstanceState);
        Button button = findViewById(R.id.button);
        Button button2 = findViewById(R.id.button2);
        Button button3 = findViewById(R.id.button3);
        editText = findViewById(R.id.editText);
        Intent intent = new Intent(DemoActivtiy.this, MyNotificationListenerService.class);//启动服务
        startService(intent);//启动服务
        final SharedPreferences sp = getSharedPreferences("msg", MODE_PRIVATE);
        button.setOnClickListener(v -> {
            String getMsg = sp.getString("getMsg", "");
            if (!StringUtils.isEmpty(getMsg)) {
                editText.setText(getMsg);
            }
        });
        button2.setOnClickListener(v -> {
            //打开监听引用消息Notification access
            Intent intent_s = new Intent(Settings.ACTION_NOTIFICATION_LISTENER_SETTINGS);
            startActivity(intent_s);
        });
        button3.setOnClickListener(v -> {
            Intent intent_p = new Intent(Settings.ACTION_APPLICATION_SETTINGS);
            startActivity(intent_p);
        });
    }
}
